package com.story.client;

import com.story.api.User;
import com.story.api.UserService;
import com.story.rpc.dto.RpcReq;
import com.story.rpc.dto.RpcResp;
import com.story.rpc.transmission.RpcClient;
import com.story.rpc.transmission.socket.client.SocketRpcClient;
import com.story.rpc.util.ThreadPoolUtils;


public class Main {
    public static void main(String[] args) {
        RpcClient rpcClient = new SocketRpcClient("127.0.0.1", 8888);
        RpcReq rpcReq = RpcReq.builder()
                .reqId("123456")
                .interfaceName("com.story.api.UserService")
                .methodName("getUser")
                .params(new Object[]{1L})
                .paramTypes(new Class[]{Long.class})
                .build();
//        RpcResp<?> rpcResp = rpcClient.sendReq(rpcReq);
//        System.out.println(rpcResp.getData());

        for(int i=0;i<10;i++){
            ThreadPoolUtils.createIoIntensiveThreadPool("test")
                    .submit(()->{
                        RpcResp<?> rpcResp1 = rpcClient.sendReq(rpcReq);
                        System.out.println(rpcResp1);
                    });
        }
    }
    private static <T> T invoke(Long id){
        RpcClient rpcClient = new SocketRpcClient("127.0.0.1", 8888);
        RpcReq rpcReq = RpcReq.builder()
                .reqId("123456")
                .interfaceName("com.story.service.UserService")
                .methodName("getUser")
                .params(new Object[]{1L})
                .paramTypes(new Class[]{Long.class})
                .build();
        RpcResp<?> rpcResp = rpcClient.sendReq(rpcReq);
        return (T) rpcResp.getData();
    }
}
